<?php

class CvController extends Controller
{
	public function actionIndex()
	{
		$uid= Yii::app()->request->getParam('uid');
		$userProfile = UserProfile::model()->findByPk($uid);
		
		if($userProfile == null)
			$userProfile = new UserProfile();
		//$UserProfile = new UserProfile();
		$provinceList = Province::model()->findAll();
		$provinceList=CHtml::listData($provinceList, 'province_id', 'province_name');
		$Gender= UserProfile::model()->getGenderList();
		
		/*if(isset($_POST['UserProfile'])){
		 $UserProfile->attributes = $_POST['UserProfile'];
		 
		}*/
		$this->render('index',array(
					'UserProfile'=>$userProfile,
					'provinceList'=>$provinceList,
		   			'Gender'=>$Gender,
		
		));
		
	}

	//add cv	
	public function actionAdd()
	{
		$uid= Yii::app()->request->getParam('uid');
		
		$userProfile = UserProfile::model()->findByPk($uid);
		if($userProfile == null)
			$userProfile = new UserProfile();
		if(isset($_POST['UserProfile'])){
			$userProfile->attributes = $_POST['UserProfile'];
			$userProfile->user_profile_user_id = $uid;
			if($userProfile->save()){
				Yii::app()->user->setFlash('success','Lưu thành công');
			}
	  		else
				throw new CHttpException('404','Error save profile');
		
			$this->redirect(array('/profile/cv/index','uid'=>$uid));
		}
	}
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}